package com.merry.spring5.validation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;
import org.springframework.validation.Validator;


/**
 * @author ybzou
 * spring实现数据校验的第二种方式。
 */
@Component
public class MyValidation2 {
    @Autowired
    private Validator validator;

    public boolean validation2(Phone2 phone2){
        BindException bindException=new BindException(phone2,phone2.getName());
        validator.validate(phone2,bindException);
        System.out.println(bindException.getAllErrors());
        return bindException.hasErrors();
    }
}
